package com.hzlx.service.impl;/*
 *@author liu
 *2024/07/2024/7/29
 *@version
 */

import com.hzlx.common.ResponseBean;
import com.hzlx.entity.CustomerBankCard;
import com.hzlx.entity.WatchList;
import com.hzlx.entity.WithdrawalRecords;
import com.hzlx.mapper.WithdrawalRecordsMapper;
import com.hzlx.service.WithdrawalRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author UP
 * @Date 2024/7/29 8:34
 * @Version 1.0
 **/

@Service
public class WithdrawalRecordsServiceImpl implements WithdrawalRecordsService {

    @Autowired
    private WithdrawalRecordsMapper withdrawalRecordsMapper;

    /**
     * 分页查询提现记录
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @Override
    public ResponseBean homeList(Integer pageIndex, Integer pageSize) {
        if (pageSize == null || pageIndex == null) {
            pageSize = 5;
            pageIndex = 1;
        }

        Integer startIndex = (pageIndex - 1) * pageSize;

        Integer count = withdrawalRecordsMapper.countGetAll(startIndex, pageSize);

        Integer total = (count) % pageSize == 0 ? count / pageSize : count / pageSize + 1;

        List<WatchList> watchVOList = withdrawalRecordsMapper.getAll(startIndex, pageSize);
        if (watchVOList != null) {
            return new ResponseBean(0, "success", watchVOList, total);
        }
        return new ResponseBean(10011, "获取失败", null);
    }

    @Override
    public ResponseBean agree(Integer flowId) {
        if(flowId == null){
            return new ResponseBean(10011,"获取订单信息失败",null);
        }
        int rows = withdrawalRecordsMapper.agree(flowId);
        if(rows>0){
            return new ResponseBean(0,"success",null);
        }
        return new ResponseBean(10012,"审核失败",null);

    }

    @Override
    public ResponseBean refuse(Integer flowId) {
        if (flowId == null){
            return new ResponseBean(10011,"获取订单信息失败",null);
        }
        int rows = withdrawalRecordsMapper.refuse(flowId);
        if (rows>0){
            return new ResponseBean(0,"success",null);
        }
        return new ResponseBean(10012,"审核失败",null);
    }
}
